﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Text.RegularExpressions;

namespace Net.Chirash.Twitter.TwitterZone
{
    /// <summary>
    /// Browser.xaml の相互作用ロジック
    /// </summary>
    public partial class OAuthBrowser : Window
    {
        public string PIN { get; set; }
        public OAuthBrowser()
        {
            InitializeComponent();
        }

        public OAuthBrowser(string url)
        {
            InitializeComponent();
            mainWebBrowser.Navigate(url);
        }

        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            Regex reg = new Regex(".*(?<pin>[0-9]{7}).*");
            if(reg.IsMatch(PINTextBox.Text))
            {
                PIN = reg.Match(PINTextBox.Text).Result("${pin}");
                PINTextBox.Text = "";
                this.Close();
            }
        }

        private void mainWebBrowser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            //スクレイピング
        }
    }
}
